package com.uzai.console.service.feign.impl;

import com.uzai.common.result.ResponseCode;
import com.uzai.console.common.UzaiRespVo;
import com.uzai.console.dto.feign.jdorder.*;
import com.uzai.console.service.feign.JdOrderFeignService;
import com.uzai.console.vo.jd.jdorder.feign.JdOrderBindVo;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: jianghan
 * @Date: 2021/11/24 16:24
 * @Description:
 */
@Component
public class JdOrderFeignFallbackFactory implements FallbackFactory<JdOrderFeignService> {

    private static Logger logger = LoggerFactory.getLogger(JdOrderFeignFallbackFactory.class);

    @Override
    public JdOrderFeignService create(Throwable throwable){

        logger.error("--京东订单调用微服务出错，err:={}", throwable);

        return  new JdOrderFeignService(){
            @Override
            public UzaiRespVo<Object> settled(JdOrderSettledDto jdOrderSettledDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> unfreeze(JdOrderUnfreezeDto jdOrderUnfreezeDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> unbind(JdOrderUnbindDto jdOrderUnbindDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> bind(JdOrderBindDto jdOrderBindDto) {
                UzaiRespVo<Object>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Boolean> pull(JdOrderPullDto jdOrderPullDto) {
                UzaiRespVo<Boolean>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Boolean> jdOrderDownload(JdOrderDownloadDto jdOrderDownloadDto) {
                UzaiRespVo<Boolean>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

        };
    }

}
